observer pattern
https://plantuml-proxy.vercel.app/svg/https://scrapbox.io/api/code/suto3/observer_pattern/o.pu#.svg
code:o.pu
@startuml
interface Subject {
+ attach(in o : Observer)
+ detach(in o : Observer)
+ notify()
}
class ConcreteSubject {
- subjectState
}
interface Observer {
+ update()
}
class ConcreteObserver {
- observerState
+ update()
}
hide empty members
Subject -> Observer : notifies
Subject <|-- ConcreteSubject
Observer <|-- ConcreteObserver
ConcreteSubject <- ConcreteObserver : observes
note as N1
<b><color:royalBlue>Observer</color></b>
<b>Type:</b> Behavioral
Define a one-to-many dependency between
objects so that when one object changes
state, all its dependents are notified and
updated automatically.
end note
@enduml